mui.init();
mui.plusReady(function(){
	//var sessionId=document.cookie.split(";")[0].split("=")[1];
 	var sessionId=(plus.navigator.getCookie("sessionId")==null)?"":plus.navigator.getCookie("sessionId");
 	//alert(sessionId);
 	
	mui.getJSON("json/locat.json", function(data) {
	
		var locat = data["url"];
		//订单列表，如果没有登录。先进行登录
			var factoryid=data["factoryid"];
			var factoryId=(plus.navigator.getCookie("factoryid")==null)?"":plus.navigator.getCookie("factoryid");
					if(factoryId != factoryid)
					window.location.href="login.html";
		mui.ajax(locat+'/clientIndex/touser?sessionId='+sessionId, {
			dataType: 'json',
			type: 'get',
			timeout: 100000,
			success: function(data) {
				if("error" == data["msg"]) 
					window.location.href = "login.html";
			},
			error: function() {
				plus.ui.toast("服务异常", "请稍后再试", "error");
				window.location.href = "login.html";
				
			}
		});

	});

})

function loginout(){
	var sessionId=(plus.navigator.getCookie("sessionId")==null)?"":plus.navigator.getCookie("sessionId");
	var loginname=plus.navigator.getCookie("loginname");
	var password=plus.navigator.getCookie("password")
	swal({
		title: "您确定要退出吗？",
		text: "",
		type: "warning",
		showCancelButton: true,
		closeOnConfirm: false,
		cancelButtonText: "取消",
		confirmButtonText: "确定",
		confirmButtonColor: "#ec6c62"
	}, function() {
		
		mui.getJSON("json/locat.json", function(data) {
	
		var locat = data["url"];
		//订单列表，如果没有登录。先进行登录
		
		mui.ajax(locat+'/clientUser/logout?sessionId='+sessionId, {
			dataType: 'json',
			type: 'get',
			timeout: 100000,
			success: function(data) {
				if("success" == data["mes"])
				plus.navigator.removeSessionCookie("sessionId");
				plus.navigator.setCookie("loginname",loginname);
				window.location.href = "login.html";
			},
			error: function() {
				plus.ui.toast("服务异常", "请稍后再试", "error");
				window.location.href = "index.html";
				
			}
		});

	});
		
		
	});
	
	
}
